package pers.vic.upload.login.controller;

import cn.xuqiudong.common.base.model.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pers.vic.upload.constant.SessionAttr;
import pers.vic.upload.login.model.User;
import pers.vic.upload.login.service.LoginService;
import pers.vic.upload.utils.SessionHelper;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalTime;


/**
 * 描述:login
 * @author Vic.xu
 * @date 2022-06-07 17:37
 */
@RestController
public class LoginController {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private LoginService loginService;

    /**
     *  login
     * @param username
     * @param password
     * @return BaseResponse
     */
    @CrossOrigin
    @RequestMapping("/login")
    public BaseResponse<?> login(String username, String password) {
        return loginService.login(username, password, request);
    }

    /**
     * logout
     * @return success
     */
    @RequestMapping("logout")
    public BaseResponse<?> logout() {
        request.getSession().invalidate();
        return BaseResponse.success();
    }
}
